home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk122 / popup / source / convert.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  4KB  |  143 lines

  1. #include "PopUpMenu.h"
  2.  
  3. /****************************************************************
  4.  * FinalSelect()  Do checkmarking and calculate Menupick value. *
  5.  *                                *
  6.  * Input:                            *
  7.  *   none                            *
  8.  * Output:                            *
  9.  *   return  - MenuPick-value or MENUNULL.            *
  10.  ****************************************************************/
  11. WORDBITS FinalSelect()
  12. {
  13.   IMPORT const UWORD  CurrentMenuNr;
  14.   IMPORT struct MenuItem *const CurrentItem, *const CurrentSubItem;
  15.   IMPORT struct WindowData ItemWindow, SubWindow;
  16.   IMPORT struct RastPort Rp;
  17.  
  18.   UWORD  SubItemNr = 31;
  19.   UWORD  ItemNr;
  20.  
  21.   if ((CurrentSubItem) AND (CurrentSubItem->Flags & ITEMENABLED)) {
  22.  
  23.     /* subitem selected -> checkmark and draw all subitems again */
  24.  
  25.     CheckMark(CurrentSubItem,SubWindow.Items);
  26.     DrawAllItems(&SubWindow);
  27.     HighLightItem(CurrentSubItem,&SubWindow,HIGHLIGHTON);
  28.  
  29.     /* clear nextselect field */
  30.     CurrentSubItem->NextSelect = MENUNULL;
  31.  
  32.     /* find the number of the selected subitem */
  33.  
  34.     SubItemNr = FindItemNr(CurrentSubItem,SubWindow.Items);
  35.  
  36.     /* remove the subitem-window so we can checkmark the items */
  37.     SwapBits(&SubWindow);
  38.   }
  39.   else
  40.     if ((CurrentItem) AND (CurrentItem->Flags & ITEMENABLED) AND
  41.     !(CurrentItem->SubItem))
  42.       CurrentItem->NextSelect = MENUNULL;
  43.     else
  44.       /* nothing is selected -> exit */
  45.       return (MENUNULL);
  46.  
  47.   CheckMark(CurrentItem,ItemWindow.Items);
  48.  
  49.   /* find number of selected item */
  50.   ItemNr = FindItemNr(CurrentItem,ItemWindow.Items);
  51.  
  52.   DrawAllItems(&ItemWindow);
  53.   HighLightItem(CurrentItem,&ItemWindow,HIGHLIGHTON);
  54.  
  55.   /* restore subwindow */
  56.   SwapBits(&SubWindow);
  57.  
  58.   return (SHIFTMENU((CurrentMenuNr - 1)) |
  59.       SHIFTITEM(ItemNr) |
  60.       SHIFTSUB(SubItemNr));
  61. }
  62.  
  63. /********************************************************
  64.  * CheckMark(Selected,Items) - Checkmark selected item. *
  65.  *                            *
  66.  * Input:                        *
  67.  *   Selected - The selected item.            *
  68.  *   Items    - All items on the same level.        *
  69.  * Output:                        *
  70.  *   none                        *
  71.  ********************************************************/
  72. VOID CheckMark(Selected,Items)
  73.   struct MenuItem *const Selected;
  74.   struct MenuItem *Items;
  75. {
  76.   if (Selected->Flags & CHECKIT) {
  77.     if (Selected->Flags & CHECKED) {
  78.       if (Selected->Flags & MENUTOGGLE)
  79.     Selected->Flags &= ~CHECKED;
  80.     }
  81.     else {
  82.       LONGBITS    Exclude = Selected->MutualExclude;
  83.  
  84.       Selected->Flags |= CHECKED;
  85.  
  86.       /* Handle mutual exclusion */
  87.  
  88.       if (Exclude)
  89.     do {
  90.       if (Exclude & 1)
  91.         Items->Flags &= ~CHECKED;
  92.       Exclude >>= 1;
  93.     }
  94.     while ((Items = Items->NextItem) != NULL);
  95.     } /* if CHECKED */
  96.   } /* if CHECKIT */
  97. }
  98.  
  99. /**********************************************
  100.  * FindMenuPtr(Number) - Find Menu structure. *
  101.  *                          *
  102.  * INPUT                      *
  103.  *   Number - Number of the menu to look for. *
  104.  * OUTPUT                      *
  105.  *   return - Ptr to the Menu structure.      *
  106.  **********************************************/
  107. struct Menu *FindMenuPtr(Number)
  108.   UWORD  Number;
  109. {
  110.   IMPORT struct Menu *const Menues;
  111.  
  112.   struct Menu *MenuPtr = Menues;
  113.  
  114.   while ((MenuPtr) AND (--Number))
  115.     MenuPtr = MenuPtr->NextMenu;
  116.  
  117.   return (MenuPtr);
  118. }
  119.  
  120. /************************************************
  121.  * FindItemNr(Item,ItemList) - Find nr of item. *
  122.  *  WARNING: The item MUST exist        *
  123.  *                        *
  124.  * Input:                    *
  125.  *   Item - Item to look for.            *
  126.  *   ItemList - all items on same level.    *
  127.  * OUTPUT                    *
  128.  *   return - Nr of Item.            *
  129.  ************************************************/
  130. UWORD  FindItemNr(Item,ItemList)
  131.   struct MenuItem *const Item;
  132.   struct MenuItem *ItemList;
  133. {
  134.   UWORD Count = 0;
  135.  
  136.   while (ItemList != Item) {
  137.     Count++;
  138.     ItemList = ItemList->NextItem;
  139.   }
  140.   return (Count);
  141. }
  142.  
  143.